<?php
/**
* @version $Id: mod_sobi2customfields.php 5203 2010-12-03 02:45:14Z  $
* @package Joomla 1.5
* @copyright Copyright (C) 2010 Miguel Puig. All rights reserved.
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
* This is a module to display A Custom fields module for Sobi2
*/

(defined( '_VALID_MOS' ) || defined( '_JEXEC' ) ) || ( trigger_error( 'Restricted access', E_USER_ERROR ) && exit() );

defined( "DS" )	|| define( "DS",DIRECTORY_SEPARATOR);

$document	= JFactory::getDocument();
$document->addStyleSheet(JURI::base() . 'modules/mod_sobi2customfields/tmpl/style.css');
$document->addStyleSheet(JURI::base() . 'modules/mod_sobi2customfields/tmpl/tango/skin.css');




$document->addScript(JURI::base() . 'modules/mod_sobi2customfields/tmpl/js/jquery-1.4.2.min.js');
$document->addScript(JURI::base() . 'modules/mod_sobi2customfields/tmpl/js/jquery.jcarousel.min.js');
$document->addCustomTag( '<script type="text/javascript">jQuery.noConflict();</script>' );



$add = 	defined( 'JPATH_SITE' ) ?  DS.'mod_sobi2customfields' : null;
defined( '_SOBI_CMSROOT' ) || define( '_SOBI_CMSROOT', str_replace( DS.'modules'.$add, null, dirname( __FILE__ ) ) );
class_exists( 'sobi2Config' ) || require_once( _SOBI_CMSROOT.DS.'components'.DS.'com_sobi2'.DS.'config.class.php' );

require_once(dirname(__FILE__).DS.'helper.php');
?>


<?php	

	$config =& sobi2Config::getInstance();
	$database =& $config->getDb();
	$S_Itemid = $config->sobi2Itemid;
	$now = $config->getTimeAndDate();
	$entryicon = $params->get('entryicon',1);
	$floatleft = $params->get('floatleft',1);
	$uniqueid = $params->get('uniqueid','carousel1');
	$text_noitems = $params->get('text_noitems');
	$show_caroussel = $params->get('show_caroussel',1);
	$item_width = $params->get('item_width',180);
	$scrollby = $params->get('scrollby',1);
	$container_width = $params->get('container_width',400);
	$item_height = $params->get('item_height',190);
	$showfieldlabel = $params->get('showfieldlabel',1);
	$showlogogallery = $params->get('showlogogallery','logo');
	$fieldsids = $params->get('fieldsids',null);
	
	$catId = $params->get('categories', 0);
	
	$entryimage = $params->get('entryimage',1);
	$showTitle = $params->get('title',1);
	$maxlength = $params->get('item_length', 50);
	$direction = $params->get('direction', 1);
	$iso = explode( '=', _ISO );
	$encoding = strtoupper($iso[1]);
	$items_final[] = array();
	
	$categories = $params->get('categories');
	$boldSetting = $params->get('boldgreeting', 0);
	$class = $params->get('moduleclass_sfx');
	$limit = $params->get('count',5);





$s_results = ModSobicustomfields::getItems($limit,$now,$catId,$config,$fieldsids);

if(count($s_results)) {

	$i = 0;
foreach($s_results as $s_result):
			
			$url = "index.php?option=com_sobi2&amp;sobi2Task=sobi2Details&amp;sobi2Id={$s_result->itemid}&amp;Itemid={$S_Itemid}";
			$url = sobi2Config::sef($url);

			$myTitle = $config->getSobiStr($s_result->title);
			$myFullTitle = $myTitle;

			$icon = null;
			if($entryicon) {
				if($s_result->icon && file_exists("{$config->absolutePath}/images/com_sobi2/clients/{$s_result->icon}")) {
					$icon = "<a href=\"{$url}\" title=\"{$myFullTitle}\"><span class=\"sobi2thumb\" ><img src=\"{$config->liveSite}/images/com_sobi2/clients/{$s_result->icon}\" title=\"{$myFullTitle}\" alt=\"{$myFullTitle}\"/></span></a>";
				}
				else{
					$icon = "<a href=\"{$url}\" title=\"{$myFullTitle}\"><span class=\"sobi2thumb\" ><img src=\"{$config->liveSite}/modules/mod_sobi2customfields/tmpl/images/no_image.png\" title=\"{$myFullTitle}\" alt=\"{$myFullTitle}\"/></span></a>";
				
				}
			}
			$gallery = null;
			if($showlogogallery=='gallery') {
				if($s_result->gallery){
					$gallid = $s_result->gallery[0]['itemid'];
					$thumb = $s_result->gallery[0]['thumb'];
					$icon = "<a href=\"{$url}\" title=\"{$myFullTitle}\"><span class=\"sobi2thumb\" ><img src=\"{$config->liveSite}/images/com_sobi2/gallery/{$gallid}/{$thumb}/\" title=\"{$myFullTitle}\" alt=\"{$myFullTitle}\"/></span></a>";
				}
			}
			
			$image = null;
			if($entryimage) {
				if($s_result->image && file_exists("{$config->absolutePath}/images/com_sobi2/clients/{$s_result->image}")) {
					$image = "<a href=\"{$url}\" title=\"{$myFullTitle}\"><span class=\"sobi2thumb\" ><img src=\"{$config->liveSite}/images/com_sobi2/clients/{$s_result->image}\" title=\"{$myFullTitle}\" alt=\"{$myFullTitle}\"/></span></a>";
				}
			}
			$e = null;
			if($showTitle) {
				if ((function_exists("mb_strlen")) && (substr($encoding,0,3) == "UTF")) {
					$len = mb_strlen($myTitle, $encoding);
				}
				else 
					$len = strlen($myTitle);
					
				if ($len > $maxlength) {
					if ((function_exists("mb_substr")) && (substr($encoding,0,3) == "UTF")) {
					   $myTitle = mb_substr($myTitle, 0,  $maxlength, $encoding);
					}
					else 
					   $myTitle = substr($myTitle, 0,  $maxlength);
					
				   $myTitle = $myTitle."...";
				}
				$e = "<a href=\"{$url}\" title=\"{$myFullTitle}\">{$myTitle}</a>";
			}


			if(isset($icon)):
				$items_final[$i]['icon'] = $icon;
			endif;
			
			if(isset($image)):
				$items_final[$i]['image'] = $image;
			endif;
			
			if(isset($e)):
				$items_final[$i]['title'] = $e;
			endif;

				$items_final[$i]['fields'] = $s_result->fields;

	$i++;		
	endforeach;




}




		$style_custom = ".jcarousel-list-horizontal{height: ".$item_height."px !important;} .xen{width:".$item_width."px !important;height: ".$item_height."px !important;}";
		$style_custom .= ".jcarousel-skin-tango .jcarousel-container-horizontal, .jcarousel-skin-tango .jcarousel-clip-horizontal{width:".$container_width."px}";
		$style_custom .= ".container{width: ".$container_width."px;} .container li{}";
    
    	if($floatleft==1):
    		$style_custom .= ".jcarousel-skin-tango li{float: left;}";
    	endif;
    	
        $document->addStyleDeclaration($style_custom); 
	
	// include the template for display
	require(JModuleHelper::getLayoutPath('mod_sobi2customfields'));

   
   ?>

